set mem 500m
set more off
cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\data"
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/data/"

use 20140308_money_d1.dta, clear


cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\output"
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/output/"
log using robust.smcl, replace


/*************************************************************Appendix 9A: Sensitivity Tests*************************************************************************************************/

/*Model 1: Province Fixed Effects*/


xi: areg reg_corrupt y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe  expand  if treatment==0 & reg_year>=2000, robust absorb(pci_id) 
outreg2 using rents_1ststage, bdec(3) tdec(3) e(all) 
predict ns_items
generate bribe=reg_corrupt-ns_items
xi: areg bribe y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe expand  if treatment==1 & reg_year>=2000, absorb(pci_id) vce(bootstrap, reps(1000)) 
estat ic
estimates store A9a_Model1
outreg2 using glynn,  bdec(3) tdec(3) e(all) replace 
drop ns_items bribe		

/*Model 2: Year Fixed Effects*/
xi: areg reg_corrupt y2011 y2012 FDI restrict equity_est FDI_res  connection_soe  expand i.reg_year  if treatment==0 & reg_year>=2000, robust absorb(pci_id) 
predict ns_items
generate bribe=reg_corrupt-ns_items
xi: areg bribe y2011 y2012 FDI restrict equity_est FDI_res  connection_soe  expand i.reg_year  if treatment==1 & reg_year>=2000, absorb(pci_id) vce(bootstrap, reps(1000)) 
estat ic
estimates store A9a_Model2
outreg2 using glynn,  bdec(3) tdec(3) e(all)
drop ns_items bribe
             
			
/*Model 3: Glynn*/
/*Step 1 and Step 2*/
foreach num of numlist 1(1)3 {
generate reg_`num'=1 if reg_corrupt>=`num'
replace reg_`num'=0 if reg_corrupt<`num'

/*Step 3*/
logit reg_`num' y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe expand if treatment==1 & reg_year>=2000 , cluster(pci_id) 
mfx
outreg2 using glynn, e(all) tdec(3) bdec(3) mfx
predict bribe`num'
/*Step 5*/
logit reg_`num' y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe  expand if treatment==0 & reg_year>=2000, cluster(pci_id) 
mfx
outreg2 using glynn, e(all) tdec(3) bdec(3) mfx 
predict ns`num'
/*Step 6*/
generate diff`num'=bribe`num'-ns`num'
}

generate full_difference=diff1+diff2+diff3
replace full_difference=0 if full_difference<0
reg full_difference y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe  expand if reg_year>=2000, cluster(pci_id) vce(bootstrap, reps(1000))
estat ic
estimates store A9a_Model3
outreg2 using glynn, e(all) tdec(3) bdec(3) excel


drop  reg_2 reg_3  bribe* ns* diff* 

   
/*Model 4: Truncated*/
xi: nbreg reg_corrupt y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe  expand if treatment==0 & reg_year>=2000, robust cluster(pci_id)
outreg2 using rents_1ststage, bdec(3) tdec(3) e(all) 
predict ns_items
generate bribe=reg_corrupt-ns_items
replace bribe=0 if bribe<0
nl (bribe = {b0}+{b1}*y2011+{b2}*y2012 +{b3}*FDI+{b4}*restrict+{b5}*FDI_res+{b6}*equity_est+{b7}*time+{b8}*time_sq+{b9}*connection_soe+{b10}*expand) if treatment==1 & reg_year>=2000, cluster(pci_id) vce(bootstrap, reps(1000))   variables (y2011 y2012 FDI restrict equity_est FDI_res time time_sq connection_soe expand)
mfx
estat ic
estimates store A9a_Model4
outreg2 using glynn, mfx bdec(3) tdec(3) e(all) excel
drop ns_items bribe



/*******************************************************************************Instrumented************************************************************************************/

/*Model 5 IV-2SLS*/

#delimit;
set more off;
xi: nbreg reg_corrupt y2011 y2012 FDI predict_restrict2 equity_est FDI_predict2 time time_sq connection_soe  expand if treatment==0 & reg_year>=2000, cluster(pci_id) vce(bootstrap, reps(1000));
outreg2 using rents_1ststage, bdec(3) tdec(3) e(all) ;
#delimit;
predict ns_items;
generate bribe=reg_corrupt-ns_items;
nl (bribe = {b0}+{b1}*y2011+{b2}*y2012 +{b3}*FDI+{b4}*predict_restrict2+{b5}*equity_est+{b6}*FDI_predict2+{b7}*time+{b8}*time_sq+{b9}*connection_soe+{b10}*expand) if treatment==1 & reg_year>=2000, cluster(pci_id) vce(bootstrap, reps(1000))    variables (y2011 y2012 FDI predict_restrict2 equity_est FDI_predict2 time time_sq connection_soe  expand);
mfx;
estat ic;
estimates store A9a_Model5;
outreg2 using glynn, mfx bdec(3) tdec(3) e(all)  excel;
drop ns_items bribe;



/****************************************************************** Robustness Profits and Restrictions / For Appendix A9a ***************************************************************/
/*Merge and First Stage*/
#delimit cr
set more off
reg ln_profit restrict i.reg_year i.year, robust cluster(isic_rev4_4digit)
predict p_profit if performance !=.
predict p_residual if performance !=., residual 
g FDI_p_profit=FDI*p_profit
g FDI_p_residual=FDI*p_residual



/*Model 6*/
set more off
xi: nbreg reg_corrupt y2011 y2012 FDI p_profit FDI_p_profit equity_est time time_sq connection_soe expand if treatment==0 & reg_year>=2000, robust cluster(isic_rev4_4digit)
outreg2 using rents_profit_robust, bdec(3) tdec(3) e(all) replace
predict ns_items
generate bribe=reg_corrupt-ns_items
nl (bribe = {b0}+{b1}*y2011+{b2}*y2012 +{b3}*FDI+{b4}*p_profit+{b5}*FDI_p_profit+{b6}*equity_est+{b7}*time+{b8}*time_sq+{b9}*connection_soe+{b10}*expand) if treatment==1 & reg_year>=2000, cluster(isic_rev4_4digit) vce(bootstrap, reps(1000)) ///
   variables (y2011 y2012 FDI p_profit FDI_p_profit equity_est time time_sq connection_soe expand)
estat ic
estimates store A9a_Model6
mfx
outreg2 using glynn, mfx bdec(3) tdec(3) e(all)
drop ns_items bribe

/*Model 7*/
xi: nbreg reg_corrupt y2011 y2012 FDI p_residual FDI_p_residual equity_est time time_sq connection_soe expand if treatment==0 & reg_year>=2000, robust cluster(isic_rev4_4digit)
outreg2 using rents_profit_robust, bdec(3) tdec(3) e(all) 
predict ns_items
generate bribe=reg_corrupt-ns_items
nl (bribe = {b0}+{b1}*y2011+{b2}*y2012+{b3}*FDI+{b4}*p_residual+{b5}*FDI_p_residual+{b6}*equity_est+{b7}*time+{b8}*time_sq+{b9}*connection_soe+{b10}*expand) if treatment==1 & reg_year>=2000, cluster(isic_rev4_4digit) vce(bootstrap, reps(1000)) ///
   variables (y2011 y2012 FDI p_residual FDI_p_residual equity_est time time_sq connection_soe expand)
estat ic
estimates store A9a_Model7
mfx, force
outreg2 using glynn, mfx bdec(3) tdec(3) e(all) excel
drop ns_items bribe


#delimit;
lrtest T2_Model1 A9a_Model1, stats force;
lrtest T2_Model1 A9a_Model2, stats force;
lrtest T2_Model1 A9a_Model3, stats force;
lrtest T2_Model1 A9a_Model4, stats force;
lrtest T2_Model1 A9a_Model5, stats force;
lrtest T2_Model1 A9a_Model6, stats force;
lrtest T2_Model1 A9a_Model7, stats force;
#delimit;
log close;

cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\do";
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/do/";
